home *** CD-ROM | disk | FTP | other *** search
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.TextField;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.midlet.MIDletStateChangeException;
-
- public class FunSnake extends MIDlet implements CommandListener {
- private Command exitCommand = new Command("Exit", 7, 2);
- private Command newGameCommand = new Command("New", 4, 2);
- private Command returnCommand = new Command("Return", 4, 2);
- private Display display = Display.getDisplay(this);
- private FunSnakeCanvas screen;
- private Form form = new Form("Bad Snake");
- private TextField speed = new TextField("Speed: 0-9", "4", 1, 2);
- private TextField level = new TextField("Level: 0-5", "0", 1, 2);
- private TextField size = new TextField("Size: 2-5", "3", 1, 2);
-
- public FunSnake() {
- this.form.append(this.speed);
- this.form.append(this.level);
- this.form.append(this.size);
- this.form.addCommand(this.exitCommand);
- this.form.addCommand(this.newGameCommand);
- this.form.setCommandListener(this);
- }
-
- public void startApp() throws MIDletStateChangeException {
- this.display.setCurrent(this.form);
- }
-
- public void pauseApp() {
- }
-
- public void destroyApp(boolean var1) {
- }
-
- public void commandAction(Command var1, Displayable var2) {
- if (var1 == this.exitCommand) {
- this.destroyApp(false);
- ((MIDlet)this).notifyDestroyed();
- } else if (var1 == this.newGameCommand) {
- int var3 = Integer.parseInt(this.speed.getString());
- int var4 = Integer.parseInt(this.level.getString());
- int var5 = Integer.parseInt(this.size.getString());
- short var6 = 300;
- switch (var3) {
- case 0:
- var6 = 500;
- break;
- case 1:
- var6 = 450;
- break;
- case 2:
- var6 = 400;
- break;
- case 3:
- var6 = 350;
- break;
- case 4:
- var6 = 300;
- break;
- case 5:
- var6 = 250;
- break;
- case 6:
- var6 = 200;
- break;
- case 7:
- var6 = 150;
- break;
- case 8:
- var6 = 100;
- break;
- case 9:
- var6 = 50;
- }
-
- this.screen = new FunSnakeCanvas(var6, var4, var5);
- this.screen.addCommand(this.exitCommand);
- this.screen.addCommand(this.returnCommand);
- this.screen.setCommandListener(this);
- this.display.setCurrent(this.screen);
- } else if (var1 == this.returnCommand) {
- this.screen.snakeTimer.cancel();
- this.screen = null;
- this.display.setCurrent(this.form);
- }
-
- }
- }
-